﻿using FastReport;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Butcher.winform.EnterpriseForms.ApproachList;
using static Butcher.winform.EnterpriseForms.WhiteNoteList;
using Traceability.Commont.DTOs;

namespace Butcher.winform.EnterpriseForms.ReportForm
{
    public partial class RegistrationDetailsForEntry : Form
    {
        public RegistrationDetailsForEntry()
        {
            InitializeComponent();
        }
        public string frx;
        private void RegistrationDetailsForEntry_Load(object sender, EventArgs e)
        {
            Report report = new Report();
            if (!string.IsNullOrWhiteSpace(frx))
                report.Load(frx);




            string url = @"http://localhost:5229/api/Enterprise/SelectApproachList";
            HttpClient client = new HttpClient();
            ApproachSelectDTO approach = new ApproachSelectDTO();
            approach.pageIndex = 1;
            approach.pageSize = 100;
            approach.ApproachTime = null;
            approach.Suppliers = "";
            approach.SettlementType = "";
            approach.ApproachStatus = -1;
            var content = new StringContent(JsonSerializer.Serialize<ApproachSelectDTO>(approach));
            content.Headers.Remove("Content-Type");
            content.Headers.Add("Content-Type", "application/json");
            string result = client.PostAsync(url, content).Result.Content.ReadAsStringAsync().Result;
            JObject info = JObject.Parse(result);
            var results = info["lists"].Value<JArray>();

            // 加载报表模板，这里假设模板文件是 "YourReportTemplate.frx"
            report.Load(@"../../../FastReport\\FastREport模版\进场登记明细表\333.frx");
            DataSet ds = new DataSet();
            DataTable fr_dt = new DataTable();
            fr_dt.TableName = "baseInfoK";
            fr_dt.Columns.Add("patName", typeof(String));//*****列名设置需要与标签模板一致*****
            fr_dt.Columns.Add("patset", typeof(String));
            fr_dt.Columns.Add("patone", typeof(String));
            fr_dt.Columns.Add("pattwo", typeof(String));
            fr_dt.Columns.Add("patthree", typeof(String));
            fr_dt.Columns.Add("patfour", typeof(String));
            fr_dt.Columns.Add("patfive", typeof(String));
            fr_dt.Columns.Add("patsix", typeof(String));
            fr_dt.Columns.Add("patsever", typeof(String));
            fr_dt.Columns.Add("pateight", typeof(String));
            fr_dt.Columns.Add("patnine", typeof(String));
            fr_dt.Columns.Add("patten", typeof(String));
            fr_dt.Columns.Add("topone", typeof(String));
            fr_dt.Columns.Add("toptwo", typeof(String));
            fr_dt.Columns.Add("topthree", typeof(String));
            fr_dt.Columns.Add("topfour", typeof(String));
            fr_dt.Columns.Add("topfive", typeof(String));
            fr_dt.Columns.Add("topsix", typeof(String));
            fr_dt.Columns.Add("topserver", typeof(String));
            fr_dt.Columns.Add("topeight", typeof(String));

           for (int i = 0;  i < results.Count; i++)
            {
                fr_dt.Rows.Add(results[i]["approachId"], results[i]["approachTime"], results[i]["approachNo"], results[i]["licensePlate"], results[i]["settlementType"], results[i]["suppliers"], results[i]["approachnum"], results[i]["quarantineCertificateNo"], results[i]["address"], results[i]["approachBatch"], results[i]["contact"], results[i]["identificationCard"], results[i]["approachTime"], results[i]["inUserId"], results[i]["goOutTime"], results[i]["inUserId"], results[i]["goUserId"], results[i]["approachStatus"], results[i]["goUserId"], results[i]["goUserId"]);
                
            }
            ds.Tables.Add(fr_dt);
            report.RegisterData(ds);//将数据传递至标签模板

            designerControl1.Report = report;
            //restore the design layout. Without this code, the designer tool windows will be unavailable
            designerControl1.RefreshLayout();
        }


        public class EMpty
        {

        }
    }
}
